package com.somsoft.handjc.activity.jiancha.xuncha;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.somsoft.handjc.activity.R;
import com.somsoft.handjc.util.BaseActivity;
import com.somsoft.handjc.util.MyApplication;

public class ZhongHeJcQueryActivity extends BaseActivity {
	
	private Button btnSubmit = null;
	private Button btnClear = null;
	private Button btnReset = null;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyApplication.getInstance().addActivity(this);
		setContentView(R.layout.xuncha_jc_query);
		setTitle("效能巡查—综合监察查询条件");
		btnSubmit = (Button)findViewById(R.id.xj_jc_btnSubmit);
		btnClear = (Button)findViewById(R.id.xj_jc_btnClear);
		btnReset = (Button)findViewById(R.id.xj_jc_btnReset);
		
		btnSubmit.setOnClickListener(new OnClickListenerImpl());
		btnClear.setOnClickListener(new OnClickListenerImpl());
		btnReset.setOnClickListener(new OnClickListenerImpl());
		
	}
	
	private class OnClickListenerImpl implements OnClickListener{

		@Override
		public void onClick(View v) {
			Button btn = (Button)v;
			EditText xc_jc_deptName = (EditText)findViewById(R.id.xc_jc_deptName);
			EditText xj_jc_startDate = (EditText)findViewById(R.id.xj_jc_startDate);
			EditText xj_jc_endDate = (EditText)findViewById(R.id.xj_jc_endDate);
			
			Intent it = new Intent(ZhongHeJcQueryActivity.this,ZhongHeJcActivity.class);
			if("查询".equals(btn.getText())){
				it.putExtra("xc_jc_deptName", xc_jc_deptName.getText().toString());
				it.putExtra("xj_jc_startDate", formatDate(xj_jc_startDate.getText().toString()));
				it.putExtra("xj_jc_endDate", formatDate(xj_jc_endDate.getText().toString()));
				startActivity(it);
			}else if("清空".equals(btn.getText())){
				xc_jc_deptName.setText("");
				xj_jc_startDate.setText("");
				xj_jc_endDate.setText("");
			}else if("重置".equals(btn.getText())){
				startActivity(it);
			}
		}
		
		private String formatDate(String date){
			//20120801转换为2012-08-01
			if("".equals(date)){
				return "";
			}
			String temp = "";
			temp += date.substring(0,4)+"-";
			temp += date.substring(4,6)+"-";
			temp += date.substring(6,8);
			return temp;
		}
	}
}
